<% page_title @stage.name %>

<%= breadcrumb @project, @stage %>

<%= render_lock @stage %>

<h1>
  <%= @stage.name %>
  <%= image_tag project_stage_path(@project, @stage, format: :svg, token: Rails.application.config.samson.badge_token), title: "Deploy badge" %>
</h1>

<section>
  <h2>Actions</h2>
  <div>
    <%= deploy_link @project, @stage %>

    <%= render "locks/button", lock: @stage.lock, resource: @stage %>

    <% if admin_for_project? %>
      <%= link_to "Edit", edit_project_stage_path(@project, @stage), class: "btn btn-default" %>
      <%= link_to_delete_button([@project, @stage]) %>
    <% end %>

    <div class="pull-right">
      <%= link_to_history @stage %>
    </div>
  </div>

  <%= render 'shared/dashboard', resource: @stage %>

  <%= Samson::Hooks.render_views(:stage_show, self) %>

  <div id="script-section">
    <h2>Script</h2>
    <pre class="pre-command"><%= "set -ex\n" + @stage.script %></pre>
  </div>

  <% if groups = @stage.deploy_groups.sort_by(&:natural_order).to_a.presence %>
    <h2>Deploy groups</h2>
    <% groups.each do |group| %>
      <%= link_to group.name, group %>
    <% end %>
  <% end %>

  <h2>Recent deploys</h2>
  <%= render "deploys/table" %>
</section>
